package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.ComposeSubject;

/**
 * 
 * @author 
 *
 */
@DAO
public interface ComposeSubjectDAO{
	
	@SQL("SELECT a.id,b.name AS gameName,c.name AS gradeName,a.subjectNo,a.title,a.type FROM ComposeSubject a JOIN Game b ON a.gameId=b.id JOIN Grade c ON a.gradeId=c.id WHERE a.deleteFlag=1 #if(:t.gameId!=-1){ AND a.gameId=:t.gameId } #if(:t.gradeId!=-1){ AND a.gradeId=:t.gradeId } ORDER BY b.updateAt DESC,c.id,a.subjectNo LIMIT :t.start,:t.length")
    List<ComposeSubject> query(@SQLParam("t") ComposeSubject composeSubject);
    
	@SQL("SELECT COUNT(0) FROM ComposeSubject a JOIN Game b ON a.gameId=b.id JOIN Grade c ON a.gradeId=c.id WHERE a.deleteFlag=1 #if(:t.gameId!=-1){ AND a.gameId=:t.gameId } #if(:t.gradeId!=-1){ AND a.gradeId=:t.gradeId }")
	int querySize(@SQLParam("t") ComposeSubject composeSubject);
	
    @SQL("select * from ComposeSubject where id=:1")
    ComposeSubject queryById(int id);
    
	@SQL("UPDATE ComposeSubject SET gameId=:t.gameId,gradeId=:t.gradeId,subjectNo=:t.subjectNo,type=:t.type,title=:t.title,content=:t.content,updateAt=NOW(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") ComposeSubject composeSubject);
    
    @SQL("UPDATE ComposeSubject SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("SELECT * FROM ComposeSubject WHERE deleteFlag=1 AND gameId=:1 AND gradeId=:2")
    List<ComposeSubject> queryByGameIdAndGradeId(int gameId,int gradeId);
    
    @SQL("SELECT * FROM ComposeSubject WHERE deleteFlag=1 AND gameId=:1")
    List<ComposeSubject> queryByGameId(int gameId);

    @SQL("INSERT INTO ComposeSubject (gameId,gradeId,subjectNo,type,title,content,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:1,:2,:3,:4,:5,:6,1,NOW(),:7,NOW(),:7)")
	void create(int gameId, int gradeId, int subjectNo, int type, String title, String content, String account);
    
    @SQL("SELECT * FROM ComposeSubject WHERE deleteFlag=1 ")
    List<ComposeSubject> querySubjectAll();
}